home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Meeting Pearls 2
/
Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso
/
Pearls
/
dev
/
Oberon4Amiga
/
Dialogs
/
DialogButtons.Mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1994-11-28
|
8KB
|
190 lines
Syntax10.Scn.Fnt
Syntax10i.Scn.Fnt
StampElems
Alloc
27 Oct 94
Syntax10b.Scn.Fnt
Chicago10.Scn.Fnt
MODULE DialogButtons; (* ww *)
(** extended version Markus Knasm
ller 25.May.94 -
IMPORT DialogFrames, Dialogs, DialogStaticTexts, DialogTexts, Display, Files, Fonts, GraphicUtils, In, Input,
Oberon, TextFrames, Texts, Viewers;
CONST ML = 0; MM = 1; MR = 2; W* = 30; H* = 20; grey1 = 12; grey2 = 13; grey3 = 14; black = 15; white = 0;
TYPE
Item* = POINTER TO ItemDesc;
ItemDesc* = RECORD(Dialogs.ObjectDesc)
fnt-: Fonts.Font; (** font that is used to display the name of the button *)
END;
VAR w0: Texts.Writer;
PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object);
(** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
VAR x: Item;
BEGIN
IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END;
b.Copy^ (dup); x.fnt := b.fnt;
END Copy;
PROCEDURE (b: Item) Draw1 (x, y: INTEGER; pressed: BOOLEAN; f: Display.Frame);
VAR mode, w, h, yh, ox, oy, cx: INTEGER;
BEGIN
b.GetDim (ox, oy, w, h);
IF b.selected THEN mode := Display.invert ELSE mode := Display.paint END;
GraphicUtils.DrawBox (f, pressed, x, y, w, h, mode);
yh := y + (h DIV 2) - ((b.fnt.minY + b.fnt.maxY) DIV 2);
IF h - (yh - y) > b.fnt.maxY THEN
GraphicUtils.DrawString (f, b.name, x + 3, yh, w - 4, b.fnt, mode, cx)
END
END Draw1;
PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
(** displays the object at (x, y) in frame f *)
BEGIN b.Draw1 (x, y, FALSE, f)
END Draw;
PROCEDURE (b: Item) Print* (x, y: INTEGER);
(** prints the object at printer coordinates (x, y) *)
VAR w, h, ox, oy, yh, cx: INTEGER; fnth: LONGINT;
BEGIN
b.GetPDim (ox, oy, w, h); GraphicUtils.PrintBox (x, y, w, h);
fnth := ((b.fnt.maxY - b.fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2;
yh := y + (h DIV 2) - SHORT (fnth);
IF h - (yh - y) > ((b.fnt.maxY * SHORT (Dialogs.dUnit)) DIV Dialogs.pUnit) THEN
GraphicUtils.PrintString (b.name, x + 3, yh, w - 4, b.fnt, cx)
END
END Print;
PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel; x0, y0: INTEGER);
VAR bx, by, bw, bh: INTEGER; keysum: SET; t: Texts.Text;
BEGIN
b.GetDim (bx, by, bw, bh);
IF (keys = {ML}) OR (keys = {MM}) OR (keys = {MR}) THEN
Oberon.RemoveMarks(x0 + bx, y0 + by, bw, bh);
b.Draw1 (x0 + bx, y0 + by, TRUE, f);
keysum := keys;
REPEAT Input.Mouse(keys, x, y); keysum := keysum + keys;
Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
UNTIL keys = {};
Oberon.RemoveMarks(x0 + bx, y0 + by, bw, bh);
b.Draw1 (x0 + bx, y0 + by, FALSE, f);
IF (keysum = {ML}) OR (keysum = {MM}) OR (keysum = {MR}) THEN
IF b.cmd[0] # 0X THEN
DialogTexts.GetParText (b.par, p, t);
b.CallCmd (f, Viewers.This (x, y), t)
END
END
ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
END
END Track;
PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
(** handles messages which were sent to frame f *)
BEGIN
b.Handle^ (f, m);
WITH f: DialogFrames.Frame DO
WITH m: Oberon.InputMsg DO
IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel, f.X, f.Y + f.H) END
ELSE
END
ELSE
END
END Handle;
PROCEDURE (b: Item) Load* (VAR r: Files.Rider);
(** reads the object from rider r *)
VAR fntname: ARRAY 32 OF CHAR;
BEGIN b.Load^( r); Files.ReadString (r, fntname); b.fnt := Fonts.This (fntname);
END Load;
PROCEDURE (b: Item) Store* (VAR r: Files.Rider);
(** writes the object to rider r *)
BEGIN b.Store^ (r); Files.WriteString (r, b.fnt.name)
END Store;
PROCEDURE (b: Item) SetFont* (fnt: Fonts.Font);
(** sets the font with which the text is shown *)
BEGIN b.fnt := fnt; b.Restore (); IF b.panel # NIL THEN b.panel.MarkMenu END
END SetFont;
PROCEDURE WriteToObjectStr (o: DialogTexts.Item; VAR p: Dialogs.Panel; n: ARRAY OF CHAR);
VAR t: Texts.Text;
BEGIN
t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
END WriteToObjectStr;
PROCEDURE (b: Item) Edit* ();
(** opens a dialog for editing the properties of the object *)
VAR on: Dialogs.Object; t: Texts.Text; fnt: Fonts.Font;
BEGIN
b.Edit^ ();
on := Dialogs.editPanel.NamedObject ("name"); t := on(DialogTexts.Item).GetText ();
Texts.ChangeLooks (t, 0, t.len, {0}, b.fnt, 0, 0);
END Edit;
PROCEDURE (b: Item) Update* (p: Dialogs.Panel);
(** sets the properties of the object to the values defined in the dialog p opened with Edit *)
VAR o: Dialogs.Object; t: Texts.Text; r: Texts.Reader; ch: CHAR;
BEGIN
o := p.NamedObject ("name"); t := o(DialogTexts.Item).GetText ();
Texts.OpenReader (r, t, 0); Texts.Read (r, ch);
IF (r.fnt # NIL) & (r.fnt # b.fnt) THEN b.SetFont (r.fnt) END;
b.Update^ (p);
END Update;
PROCEDURE Insert*;
(** Insert ([name] [x y w h] | ^ ) inserts a button - item in the panel containing the caret position *)
VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
BEGIN
NEW (b);
DialogFrames.GetCaretPosition(p, x, y);
IF (p # NIL) THEN
b.Init; b.fnt := Fonts.This ("Syntax10b.Scn.Fnt");
In.Open; In.Name (name);
IF ~In.Done THEN COPY ("", name); In.Open END;
b.SetName (name);
In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H
ELSE
IF w < 0 THEN w := W END;
IF h < 0 THEN h := H END
END;
b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE)
ELSE
Dialogs.res := Dialogs.noPanelSelected
END;
IF Dialogs.res # 0 THEN Dialogs.Error ("DialogButtons") END;
END Insert;
PROCEDURE DeInit;
VAR s: DialogStaticTexts.Item; b: Item; t: DialogTexts.Item;
BEGIN
NEW (Dialogs.deInit);
NEW (s); s.Init; s.SetDim (6, -36, 45, 20, FALSE);
s.SetString ("Name"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (13, -79, 40, 20, FALSE);
s.SetString ("X"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (13, -117, 40, 20, FALSE);
s.SetString ("Y"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (8, -155, 40, 20, FALSE);
s.SetString ("Cmd"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (155, -79, 19, 18, FALSE);
s.SetString ("W"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (153, -116, 19, 18, FALSE);
s.SetString ("H"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (8, -193, 40, 20, FALSE);
s.SetString ("Par"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (b); b.Init; b.SetDim (288, -107, 80, 35, FALSE); b.SetName ("Do");
b.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); b.SetCmd ("Dialog.Do");
Dialogs.deInit.Insert (b, FALSE);
NEW (t); t.Init; t.SetDim (52, -40, 140, 25, FALSE); t.SetName ("name");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (54, -79, 70, 22, FALSE); t.SetName ("x");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (54, -116, 70, 22, FALSE); t.SetName ("y");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (54, -155, 195, 22, FALSE); t.SetName ("cmd");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (177, -79, 70, 22, FALSE); t.SetName ("w");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (177, -117, 70, 22, FALSE); t.SetName ("h");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (54, - 193, 195, 22, FALSE); t.SetName ("par");
Dialogs.deInit.Insert (t, FALSE)
END DeInit;
BEGIN Texts.OpenWriter (w0); DeInit;
END DialogButtons.